package gorails.com;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class LineListAdapter extends ArrayAdapter<String> {
	private  ArrayList<String> values;
	private LayoutInflater inflator;
	private Context context;
	ImageView icon = null;
	ImageView iconlist[] = null;
	private static int iCount=0;
	public LineListAdapter(Context context, int textViewResourceId, ArrayList<String> values) {
		super(context, textViewResourceId, values);
		this.values= new ArrayList<String>(values);
		inflator = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.context = context;
		
		iconlist = new ImageView[values.size()];
		
	}

	public void updateValues(ArrayList<String> values){
		this.values = values;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		String o = values.get(position);
		
		View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.rowlayout, null);            
            icon = (ImageView) v.findViewById(R.id.icon);
            
        }        
        if (o != null) {
                TextView tt = (TextView) v.findViewById(R.id.listitem);
                String[] a = new String[] { "Union Pacific North", "Milwaukee District North", "North Central Service", "Union Pacific Northwest",
    	         		"Milwaukee District West", "Union Pacific West", "BNSF Railway", "Heritage Corridor", "Southwest Service","Rock Island District",
    	         		"Metra Electric District"};

                if (o.equalsIgnoreCase(a[0])){    			
    				icon.setBackgroundColor(Color.rgb(0, 192, 0));
                }
                else if(o.equalsIgnoreCase(a[1])){
                	icon.setBackgroundColor(Color.rgb(192, 143, 33));
                }
                else if(o.equalsIgnoreCase(a[2])){
                	icon.setBackgroundColor(Color.rgb(192, 0, 192));
                }
                else if(o.equalsIgnoreCase(a[3])){
                	icon.setBackgroundColor(Color.rgb(255, 255, 0));
                }
                else if(o.equalsIgnoreCase(a[4])){
                	icon.setBackgroundColor(Color.rgb(255, 167, 29));
                }
                else if(o.equalsIgnoreCase(a[5])){
                	icon.setBackgroundColor(Color.rgb(255, 192, 255));
                }
                else if(o.equalsIgnoreCase(a[6])){
                	icon.setBackgroundColor(Color.rgb(0, 192, 0));
                }
                else if(o.equalsIgnoreCase(a[7])){
                	icon.setBackgroundColor(Color.rgb(192, 0, 0));
                }
                else if(o.equalsIgnoreCase(a[8])){
                	icon.setBackgroundColor(Color.rgb(0, 0, 192));
                }
                else if(o.equalsIgnoreCase(a[9])){
                	icon.setBackgroundColor(Color.rgb(187, 1, 1));
                }
                else if(o.equalsIgnoreCase(a[10])){
                	icon.setBackgroundColor(Color.rgb(217, 101, 101));
                }
                else{
                	//Toast.makeText(context, "default Error " , Toast.LENGTH_LONG).show();
                }	
    			
                
                if (tt != null) {
                      tt.setText(o);                            
                }
        		
        }
        return v;
		
	}
}